import jakarta.servlet.ServletException;
import jakarta.servlet.annotation.WebServlet;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;

import java.io.IOException;
import java.util.Arrays;
import java.util.Map;
import java.util.Set;

@WebServlet("/request3")
public class request3 extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String username = req.getParameter("username");
        String password = req.getParameter("password");
        System.out.println("username:"+username+"password:"+password);
        System.out.println("=======================");
        String username1 = req.getParameter("username");
        String password1 = req.getParameter("password");
        String nickname = req.getParameter("nickname");
        String email = req.getParameter("email");
        System.out.println(username1+"..."+password1+"..."+nickname+"..."+email);

        System.out.println("==============");
        //request.getParameterValues("请求参数的name属性名") 适用于多个参数
        String[] hobbies = req.getParameterValues("hobby");
        System.out.println("hobbies:"+ Arrays.toString(hobbies));
        System.out.println("===============");
        /*
          request.getParameterMap() ->获取提交请求的所有参数,以键值对的方式 存到map
          map中的key:页面上name的属性值
          value:页面上value的属性值
         */
        Map<String, String[]> parameterMap = req.getParameterMap();
        Set<Map.Entry<String, String[]>> entries = parameterMap.entrySet();
        for (Map.Entry<String, String[]> entry : entries) {
            System.out.println(entry.getKey()+":"+Arrays.toString(entry.getValue()));
        }


    }


    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
      doGet(req,resp);
    }
}
